package com.bxkc.generator.enums;

import java.sql.JDBCType;

/**
 * 数据库数据类型和java 实体类映射关系
 * 2019-10-28 21:56
 *
 * @author LCY
 */
public enum ColumnDataTypeEnum {
    BIGINT("bigint",JDBCType.BIGINT,"Long","java.lang.Long",false),
    INTEGER ("integer",JDBCType.INTEGER,"Integer","",false),
    INT ("int",JDBCType.INTEGER,"Integer","",false),
    LONG ("long",JDBCType.BIGINT,"Long","java.lang.Long",false),
    SHORT ("short",JDBCType.SMALLINT,"Short","",false),
    FLOAT ("float",JDBCType.FLOAT,"Float","java.lang.Float",false),
    DOUBLE ("double",JDBCType.DOUBLE,"Double","",false),
    BIG_DECIMAL ("big_decimal",JDBCType.NUMERIC,"BigDecimal","java.math.BigDecimal",true),
    DATE ("date",JDBCType.DATE,"Date","java.util.Date ",true),
    TIME ("time",JDBCType.TIME,"Date","java.util.Date ",true),
    TEXT ("text",JDBCType.CLOB,"String","",false),
    LONG_TEXT ("longtext",JDBCType.CLOB,"String","",false),
    CLOB ("clob",JDBCType.CLOB,"String","",false),
    VARCHAR ("VARCHAR",JDBCType.VARCHAR,"String","",false),
    CHAR ("CHAR",JDBCType.CHAR,"String","",false),
    BLOB ("blob",JDBCType.BLOB,"byte[]","",false),
    TIMESTAMP("timestamp",JDBCType.DATE,"Date","java.Util.Date",true),
    BINARY("binary",JDBCType.BINARY,"byte[]","",false),
    BIT("bit",JDBCType.BIT,"Boolean","",false),
    DECIMAL("decimal",JDBCType.DECIMAL,"BigDecimal","java.math.BigDecimal",true),
    MONEY("money",JDBCType.DECIMAL,"BigDecimal","java.math.BigDecimal",true),
    SMALLMONEY("smallmoney",JDBCType.DECIMAL,"BigDecimal","java.math.BigDecimal",true),
    IMAGE("image",JDBCType.LONGVARBINARY,"byte[]","",false),
    VARBINARY("varbinary",JDBCType.LONGVARBINARY,"byte[]","",false),
    NCHAR("nchar",JDBCType.CHAR,"String","",false),
    NVARCHAR("nvarchar",JDBCType.VARCHAR,"String","",false),
    NTEXT("ntext",JDBCType.LONGNVARCHAR ,"String","",false),
    NUMERIC("numeric",JDBCType.NUMERIC,"BigDecimal","java.math.BigDecimal",true),
    REAL("real",JDBCType.REAL,"Float","",false),
    SMALLINT("smallint",JDBCType.SMALLINT,"Short","",false),
    DATETIME("datetime",JDBCType.TIMESTAMP,"Date","java.util.Date",true),
    VARCHAR2 ("VARCHAR2",JDBCType.VARCHAR,"String","",false),
    DATETIME2("datetime2",JDBCType.DATE,"Date","java.Util.Date",true),
    TINYINT("tinyint",JDBCType.BOOLEAN,"Boolean","",false);

    /**
     * 数据库字段类型
     */
    private String sqlDataType;
    /**
     * JDBC数据类型
     */
    private JDBCType jdbcType;
    /**
     * java 数据类型
     */
    private String javaType;
    /**
     * java 数据类型所在包
     */
    private String javaPackage;
    /**
     * 是否需要引包
     */
    private boolean isImport;

    private ColumnDataTypeEnum(String sqlDataType, JDBCType jdbcType, String javaType, String javaPackage, boolean isImport){
        this.isImport = isImport;
        this.javaPackage = javaPackage;
        this.javaType = javaType;
        this.jdbcType = jdbcType;
        this.sqlDataType = sqlDataType;
    }

    public static ColumnDataTypeEnum getBySqlDataType(String sqlDataType){
        ColumnDataTypeEnum[] values = ColumnDataTypeEnum.values();
        for (ColumnDataTypeEnum value : values) {
            if(value.getSqlDataType().equalsIgnoreCase( sqlDataType )){
                return value;
            }
        }
        return null;
    }

    public String getSqlDataType() {
        return sqlDataType;
    }

    public void setSqlDataType(String sqlDataType) {
        this.sqlDataType = sqlDataType;
    }

    public JDBCType getJdbcType() {
        return jdbcType;
    }

    public void setJdbcType(JDBCType jdbcType) {
        this.jdbcType = jdbcType;
    }

    public String getJavaType() {
        return javaType;
    }

    public void setJavaType(String javaType) {
        this.javaType = javaType;
    }

    public String getJavaPackage() {
        return javaPackage;
    }

    public void setJavaPackage(String javaPackage) {
        this.javaPackage = javaPackage;
    }

    public boolean isImport() {
        return isImport;
    }

    public void setImport(boolean anImport) {
        isImport = anImport;
    }
}
